<style>
  .list-success{
    width:110px;
    position: relative;
    margin-left:10px;
  }
  .img-close{
    padding:5px;
    position: absolute;
    left:80px;
    top:-45px;
  }
</style>
<title>文章列表</title>

<div class="layui-card layadmin-header">
  <div class="layui-breadcrumb" lay-filter="breadcrumb">
    <a lay-href="">主页</a>
    <a><cite>文章管理</cite></a>
    <a><cite>文章列表</cite></a>
  </div>
</div>

<div class="layui-fluid">
  <div class="layui-card">
<form class="layui-form" action="">
  <div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list"style="padding: 20px 30px 0 0;">
    <div class="layui-form-item">
      <label class="layui-form-label">标题</label>
      <div class="layui-input-inline">
          <input type="text" name="title" value="" lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">所属分类</label>

      <div class="layui-input-inline">
        <div class="layui-input-inline" lay-filter="layadmin-layout-right">
          <select name="news_type_id" id="parent_id" lay-verify="required">

          </select>
        </div>
      </div>
    </div>

    <div class="layui-form-item">
      <label class="layui-form-label">短标题</label>
      <div class="layui-input-inline">
        <input type="text" name="short_title" value="" placeholder="请输入短标题" autocomplete="off" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">关联店铺</label>
      <div class="layui-input-inline">
        <input type="text" name="mall_ids" value="" placeholder="请输入关联店铺" autocomplete="off" class="layui-input">
        <span>例：店铺id,店铺id</span>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">缩略图</label>
      <div class="layui-input-inline">
        <script type="text/html" template>
          <input type="text" readonly name="lit_pic" value="{{ d.params.lit_pic || '' }}" placeholder="请上传图片" autocomplete="off" class="layui-input" >
        </script>
      </div>
      <button style="float: left;" type="button" class="layui-btn" id="layuiadmin-upload-useradmin"  data-type="upload">上传图片</button>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">关键字</label>
      <div class="layui-input-inline">
        <input type="text" name="keywords" value="" placeholder="请输入关键字" autocomplete="off" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">描述</label>
      <div class="layui-input-block">
        <input type="text" style="width: 600px;" name="description" value="" placeholder="请输入描述" autocomplete="off" class="layui-input">
      </div>
    </div>

    <div class="layui-form-item">
      <label class="layui-form-label">标签</label>
      <div class="layui-input-inline">
          <input type="text" name="tag" value="" placeholder="请输入标签" autocomplete="off" class="layui-input">

      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">跳转地址</label>
      <div class="layui-input-inline">
        <input type="text" name="jump_url" value="" placeholder="请输入跳转地址" autocomplete="off" class="layui-input">

      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">作者</label>
      <div class="layui-input-inline">
        <input type="text" name="author" value="" placeholder="请输入作者" autocomplete="off" class="layui-input">

      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">来源</label>
      <div class="layui-input-inline">
        <input type="text" name="source_from" value="" placeholder="请输入来源" autocomplete="off" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">排序</label>
      <div class="layui-input-inline">
        <input type="text" name="sortrank" value="" placeholder="请输入排序" autocomplete="off" class="layui-input">

      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">标题颜色</label>
      <div class="layui-input-inline">
        <input type="text" name="title_color" value="" placeholder="请输入标题颜色" autocomplete="off" class="layui-input">

      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">seo优化地址</label>
      <div class="layui-input-inline">
        <input type="text" name="seo_uri" value="" placeholder="请输入seo优化地址" autocomplete="off" class="layui-input">

      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">发布时间</label>
      <div class="layui-input-inline">
        <input type="text" name="pub_time" value="" placeholder="请输入发布时间" autocomplete="off" class="layui-input">
        <span>例：2020-01-01</span>
      </div>
    </div>



    <div class="layui-form-item">
      <label class="layui-form-label">内容</label>
      <div class="layui-input-block">
          <textarea name="body" id="description" lay-verify="description" rows="80" cols="100"></textarea>
      </div>
    </div>
      <input type="hidden" name="opt" value="add">
    <div class="layui-form-item" style="padding-bottom:20px;">
      <label class="layui-form-label"></label>
      <div class="layui-input-inline">
        <input type="button" lay-submit lay-filter="layuiadmin-app-form-submit" value="确认" class="layui-btn">
      </div>
    </div>
  </div>
</form>
  </div>
</div>

  <script>
    var $;
      layui.use(['admin', 'form', 'upload', 'layedit','rate'], function(){
          $ = layui.$
              ,admin = layui.admin
              ,form = layui.form
              ,upload = layui.upload;
        var layedit = layui.layedit;
        layedit.set({
          uploadImage: {
            url: layui.setter.api+'common/do_upload' //接口url
            ,field:{'field':'file','dir':'editor'}
          }
        });
        var editIndex = layedit.build('description');
        form.verify({
          description: function(value){
            layedit.sync(editIndex);
          }
        });

        // 设置左侧锚点
        var path =  layui.router().path
                ,pathURL = layui.admin.correctRouter(path.join('/'))
                ,dataName = layui.setter.response.dataName;
        $(".layui-nav-child dd").each(function(){
          if(pathURL.indexOf($(this).attr('data-jump')) > -1){
            $(this).addClass('layui-this');
          }
        })
          // 获取分类数据
          admin.req({
              url: layui.setter.api+'news/news/cates'
              ,method:'get'
              ,success: function(data){
                  if(data.code == 0){
                      var info = data.data;
                      var html = '<option value="0">选择分类</option>';
                      for(var i =0;i<data.data.length;i++){
                          html += '<option value="'+info[i]['id']+'">'+info[i]['name']+'</option>'
                      }
                      $("#parent_id").html(html);
                      form.render();
                  }

              }
          });

        //监听提交
        form.on('submit(layuiadmin-app-form-submit)', function(data){
          var field = data.field; //获取提交的字段

          //提交 Ajax 成功后，关闭当前弹层并重载表格
          //提交修改
          admin.req({
            url: layui.setter.api+'news/news'
            ,data: data.field
            ,method:'post'
            ,success: function(data){
              if(data.code == 0){
                location.href="#/news/news";
              }else{
                layer.msg(data.msg);
              }
            }
          });
        });
        //上传头像
        upload.render({
          elem: '#layuiadmin-upload-useradmin'
          ,url: layui.setter.api+'common/do_upload'
          ,data:{'field':'file','dir':'forum'}
          ,accept: 'images'
          ,method: 'get'
          ,acceptMime: 'image/*'
          ,done: function(res){
            $(this.item).prev("div").children("input").val(res.data.src)
          }
        });

      })
  </script>
